<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="dgg-list-top-warp">
        <div class="screen-search">
            <ul>
                <li>
                    <label>所属生产事业部：</label>
                    <select id="productOrgId" name="productOrgId" >
                    </select>
                </li>
                <li>
                    <label>业务类型：</label>
                    <div name="typeCode" id="typeCode"></div>
                </li>
                <li>
                    <button class="dggui-btn" onclick="tableReload();">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch()">清空条件</button>
                    <%--<button class="dggui-btn dggui-btn-green">导出</button>--%>
                </li>
            </ul>
        </div>
    </div>
    <div class="list-content">
        <div class="tool-bar">
            <div class="fl">
                <a href="javascript:void(0)" class="dggui-btn" onclick="addFlow()">新建流程</a>
                <a href="javascript:void(0)" class="dggui-btn" onclick="addFlowNode()">流程节点编辑</a>
                <a href="javascript:void(0)" class="dggui-btn" onclick="copyFlow()">复制流程</a>
            </div>
        </div>
        <div class="table-warp">
            <table class="dggui-table" id="flowNode">

            </table>
        </div>
    </div>
</div>

<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var NORMAL = '${NORMAL}', TIME_OUT = '${TIME_OUT}';
    var tables;
    dggui.use(['table', 'select2','distpicker'], function (){
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;
        //var dggdate = dggui.dggdate;
        //初始化所属生产事业部
        syb("#productOrgId");
        select2.render({
           placeholder: "请选择",
            elem: $('#productOrgId'),
            allowClear: true,
            width: "190px"
        });
        //初始化业务类型及产品
        distpicker.render({
            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&&type=2&&level=2", // 请求地址
            elem: '#typeCode', // 容器Id
            placeholder: '选择业态',
            type:2,
            defaultParentCode:'BUS_YT_DK'
            /*callback:function () {
                select2.render({
                   placeholder: "请选择",
                    allowClear: true,
                    elem: $('#productCode'),
                    width: "190px"
                });
            }*/
        });

        var opt={
            "elem":"#flowNode",
            "ajax": sysInfo.basePath +"/rzsc/flow/search_all_node_flow.do",
            "scrollX": "true",//是否开启横项滚动
            //"selectCheck": false, //多选,同时选中复选框
            "oneSelectCheck":true,//单选，同时选中复选框
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "fnServerParams": function (aoData) {
                //搜索条件
                aoData = $.extend(aoData, {
                    //所属生产部门
                    deptIds : $("#productOrgId").val(),
                    //业务类型
                    businessCode : $('#typeCode .plug-in-code').val(),
                    //老数据
                    isOld : 0
                });
                //aoData = $.extend(aoData, $("#allScOrderForm").serializeObject());
                return aoData;
            },
            "aoColumns": [
                {
                    "sClass": "check-th",
                    "orderable": false,
                    "title": "<input type='checkbox'  class='checkall'>",
                    "render": function(data, type, full, meta) {
                        return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                    }
                },
                {
                    "title": "序号",
                    "orderable": false,
                    "render": function(data, type, full, meta) {
                        return meta.row + 1;
                    }
                },
                {
                    'title': '流程编号',
                    "orderable": false,
                    "data": "flowNo",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '适用事业部名称',
                    "orderable": false,
                    "data": "deptNames",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '大业态',
                    "orderable": false,
                    "data": "bigformatCode",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '小业态',
                    "orderable": false,
                    "data": "businessCode",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '业务办理周期',
                    "orderable": false,
                    "data": "managementCycle",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '工作日/自然日',
                    "orderable": false,
                    "data": "isnaturalorworkday",
                    "render": function (d, type, r, meta) {
                        if (d == 1) {
                            return "工作日";
                        }
                        if (d == 2) {
                            return "自然日";
                        }
                    }
                },
                {
                    'title': '审核级数',
                    "orderable": false,
                    "data": "examineGrade",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '最新更新时间',
                    "orderable": false,
                    "data": "updateTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '最后更新人',
                    "orderable": false,
                    "data": "updaterName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    'title': '操作',
                    "orderable": false,
                    "render": function(data, type, row, meta) {
                        var htm = '<a href="javascript:updateFlow(\''+row.id+'\')" class="dggui-link">修改</a>';
                        return htm;
                    }
                }
            ]
        };
        tables = table.render(opt);
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on( 'error.dt', function ( e, settings, techNote, message ) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
           if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
        });
    });
    function updateFlow(flowId){
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/flow/flowedit_tabpage.html",
            dataType:'html',
            data : {flowId : flowId},
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: '编辑流程',
                    content: res,
                    area:  '500px',
                    btn: ["确定", "取消"],
                    yes: function (index) {
                        flowUpdate(index);
                    }, btn2: function () {
                    }
                })
            }
        });
    }
    function addFlow(){
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/flow/creat_new_flow.html",
            dataType:'html',
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: '新建流程',
                    content: res,
                    area: '500px',
                    btn: ["确定", "取消"],
                    yes: function (index) {
                        flowCreate(index);
                    }, btn2: function () {
                    }
                })
            }
        });
    }
    function copyFlow(index){
        var obj = getChecked("#flowNode");
        if (obj.length < 1) {
            dggui.dialog.errors('请至少选择一条数据！');
            return;
        } else if (obj.length > 1) {
            dggui.dialog.errors('只能选择一条数据！');
            return;
        }
        var id = getIds(obj);
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath+"/rzsc/flow/flowcopy_tabpage.html",
            dataType:'html',
            data:{
                'flowId': id
            },
            success:function (res){
                dggui.dialog.loading('close');
                dggui.dialog.open({
                    title: '复制流程',
                    content: res,
                    area: '500px',
                    btn: ["确定", "取消"],
                    yes: function (index) {
                        flowCopy(index);
                    }, btn2: function () {
                    }
                })
            }
        });
    }
    function addFlowNode(){
        var obj = getChecked("#flowNode");
        if (obj.length < 1) {
            dggui.dialog.errors('请至少选择一条数据！');
            return;
        } else if (obj.length > 1) {
            dggui.dialog.errors('只能选择一条数据！');
            return;
        }

        var id = getIds(obj);
        var url = sysInfo.basePath + "/rzsc/flow/open_edit_flownode_page.html?flowId=" + id;
        //新增tabs
        window.parent.updateTab("编辑流程节点", url);
    }

    //列表刷新
    function tableReload() {
        tables.ajax.reload();
        //$("#allOrderList").dataTableExtend('reload');
    }
</script>
</body>
</html>